package com.heima.behavior.service.impl;

import com.heima.behavior.dto.FollowBehaviorDto;
import com.heima.behavior.entity.ApBehaviorEntry;
import com.heima.behavior.entity.ApFollowBehavior;
import com.heima.behavior.mapper.ApFollowBehaviorMapper;
import com.heima.behavior.service.IApBehaviorEntryService;
import com.heima.behavior.service.IApFollowBehaviorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * APP关注行为表 服务实现类
 * </p>
 *
 * @author syl
 * @since 2022-02-16
 */
@Service
public class ApFollowBehaviorServiceImpl extends ServiceImpl<ApFollowBehaviorMapper, ApFollowBehavior> implements IApFollowBehaviorService {

    @Autowired
    private IApBehaviorEntryService apBehaviorEntryService;

    @Override
    public void saveBehavior(FollowBehaviorDto followBehaviorDto) {

        ApFollowBehavior apFollowBehavior = new ApFollowBehavior();

        ApBehaviorEntry apBehaviorEntry = apBehaviorEntryService.getEntryByUserIdOrEquipmentId(followBehaviorDto);

        apFollowBehavior.setEntryId(apBehaviorEntry.getId());
        apFollowBehavior.setFollowId(followBehaviorDto.getFollowId());
        apFollowBehavior.setOperation(followBehaviorDto.getOperation());
        apFollowBehavior.setCreatedTime(new Date());
        this.save(apFollowBehavior);

    }
}
